#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <unordered_map>
#include <algorithm>

using namespace std;

bool is_simple(int x) {
  for (int d = 2; d <= sqrt(x); d++) {
    if (x % d == 0) return false;
  }
  return true;
}

vector<int> spr() {
  vector<int> sp;
  for (int i = 101; i <= 997; i++) {
    if (is_simple(i)) {
      sp.push_back(i);
    }
  }
  return sp;
}

int main() {
  unordered_map<string, char> w_digits = {
    {"zero", '0'}, {"one", '1'}, {"two", '2'}, {"three", '3'}, {"four", '4'},
    {"five", '5'}, {"six", '6'}, {"seven", '7'}, {"eight", '8'}, {"nine", '9'}
  };

  string s;
  getline(cin, s);

  string p = "";
  string delimiter = " ";
  size_t pos = 0;
  string token;
  while ((pos = s.find(delimiter)) != string::npos) {
    token = s.substr(0, pos);
    p += w_digits[token];
    s.erase(0, pos + delimiter.length());
  }
  p += w_digits[s];

  if (p.length() != 3) {
    cout << "Wrong input" << endl;
    return 1;
  }

  int p_int = stoi(p);

  vector<int> sp = spr();

  int a = *max_element(sp.begin(), sp.end(), p_int{ return (i <= p_int && (abs(p_int - i) < abs(p_int - j) || j > p_int)); });
  int b = *min_element(sp.begin(), sp.end(), p_int{ return (i >= p_int && (abs(p_int - i) < abs(p_int - j) || j < p_int)); });

  if (abs(p_int - a) > abs(p_int - b)) {
    cout << b << endl;
  } else {
    cout << a << endl;
  }

  return 0;
}
